package com.too.practice;

import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;

public class TreeSetPractice {
    public static void main(String[] args) {
        //  创建一个TreeSet对象,存储Person对象，按照年龄进行排序
        //  Scanner对象，监听键盘录入
        //开启for循环，循环3次


        TreeSet<Person> ts = new TreeSet<>(new Comparator<Person>() {
            @Override
            public int compare(Person o1, Person o2) {
                //o2-o1
                return (int) (o2.getMath() + o2.getChinese() +  o2.getEnglish() - o1.getMath() - o1.getChinese() - o1.getEnglish());
            }
        });
        Scanner scanner = new Scanner(System.in);

        for (int i = 0; i < 3; i++){
            System.out.println("请输入第 " + (i+1) + " 个人信息：");
            System.out.print("请输入姓名：");
            //录入的时候，姓名不能为空
            String name = scanner.next();
            System.out.print("请输入语文成绩：");
            double chinese = scanner.nextDouble();
            System.out.print("请输入数学成绩：");
            double math = scanner.nextDouble();
            System.out.print("请输入英语成绩：");
            double english = scanner.nextDouble();
            //创建Person对象
            Person p = new Person(name, chinese, math, english);
            //把Person对象添加到集合中
            ts.add(p);

        }
        for (Person p : ts){
            System.out.println(p);
        }
    }
}